import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-l","--lpath",help="ROUTE 文件路径")
parser.add_argument("-i","--index",help="Start Index")
parser.add_argument("-n","--num",help="需要截取的垄数")
args = parser.parse_args()

if args.lpath:
    route_path = args.lpath
else:
    parser.print_help()
    exit()

if args.index:
    index_start = int(args.index)
else:
    parser.print_help()
    exit()

if args.num:
    num = int(args.num)
else:
    parser.print_help()
    exit()

with open (route_path, 'r' ) as f:
    lines = f.readlines()

x = []
y = []
mode1 = []
mode2 = []
index = []

out_put_ROUTE = 'route_' + str(index_start) + '_' + str(num) + '.txt'

for line in lines:
    part = line.strip().split()
    x.append(float(part[1]))
    y.append(float(part[2]))
    mode1.append(int(part[3]))
    mode2.append(int(part[4]))
    index.append(int(part[5]))

with open(out_put_ROUTE, 'w') as f:
    for i in range(len(index)):
        if index[i] >= index_start and index[i] <= index_start + num:
            f.write(f'{i+1} {x[i]} {y[i]} {mode1[i]} {mode2[i]} {index[i]}\n')






